package org.example.operator;

import org.example.enums.OperEnum;
import org.example.redo.Redo;
import org.example.undo.Undo;
import com.google.common.eventbus.EventBus;

import java.util.Objects;

/**
 *
 * 操作的构建，用来构建两个数据的具体操作，加减乘除
 * @author Silver
 * @return
 */
public class OperationBuilder {

    /**
     *
     * 构建数据操作，用来初始化对应操作需要用的具体实现
     * @author Silver
     * @param undo
     * @param redo
     * @param eventBus
     * @param finalResult
     * @param operEnum
     * @return org.example.operator.ComplexNumberOperator
     */
    public static ComplexNumberOperator buildComplexNumberOperator(Undo undo, Redo redo, EventBus eventBus, ResultSource finalResult, OperEnum operEnum) throws Exception {
        ComplexNumberOperator complexNumberOperator = null;
        switch (operEnum){
            case ADD:
                complexNumberOperator = new Add();
                break;
            case SUBTRACT:
                complexNumberOperator = new Subtract();
                break;
            case MULT:
                complexNumberOperator = new Multiply();
                break;
            case DIVIDE:
                complexNumberOperator = new Divide();
                break;
        }
        if (Objects.isNull(complexNumberOperator)){
            throw new Exception("不支持加成乘除外的计算方式");
        }
//        complexNumberOperator.setUndo(undo);
//        complexNumberOperator.setRedo(redo);
        complexNumberOperator.setEventBus(eventBus);
        complexNumberOperator.setFinalResult(finalResult);
        return complexNumberOperator;
    }
}
